package com.creating.mict.dao;


import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.creating.mict.domain.Column;
import com.creating.mict.domain.MessSend;
import com.creating.mict.domain.Patient;
import com.creating.mict.domain.ReportData;
import com.creating.mict.domain.XtyRecord;
import com.creating.mict.domain.XyjRecord;



/** 
 * @ClassName: XyjDao 
 * @Description: 血压计模块Dao
 * @author xuelei
 * @date 2012-3-9 下午7:53:55 
 *  
 */
public class MessDao extends HibernateDaoSupport {

private static final Log log = LogFactory.getLog(MessDao.class);
	
	
	/**
	 * 
	* @Title: saveMessSend 
	* @Description: 保存短信发送记录
	* @param @param list
	* @param @return 
	* @return boolean    返回类型 
	* @throws
	 */
	public boolean saveMessSend(List<MessSend> list) {
		try {
			getHibernateTemplate().saveOrUpdateAll(list);
			getHibernateTemplate().flush();
			log.info("保存短信发送记录成功!");
			return true;
		} catch (DataAccessException e) {
			log.error("保存短信发送记录失败!");
			return false;
		}
	}

	
	public List<ReportData> queryRMessCountToChart(String fbtime, String fetime, String ftjlx, String loginName) {

		String sql = "";
		sql = " select trim('接收信息数目'), '', sum(1) "
			+ " from v_RMess_all  " 
			+ " where 1=1 "; 
		
		if(fbtime == null || fbtime.equals("null") || fbtime.equals("")) {
			sql += " and ( fxyj_rdate <= to_date('" + fetime + " 23:59:59','yyyy-mm-dd hh24:mi:ss') or fxty_rdate <= to_date('" + fetime + " 23:59:59','yyyy-mm-dd hh24:mi:ss') ) ";
		} else {
			sql += " and ( fxyj_rdate between to_date('" + fbtime + " 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('" + fetime + " 23:59:59','yyyy-mm-dd hh24:mi:ss') or fxty_rdate between to_date('" + fbtime + " 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('" + fetime + " 23:59:59','yyyy-mm-dd hh24:mi:ss') )";
		}
		
		Query query = this.getSession().createSQLQuery(sql);
		List list = query.list();
		List<ReportData> xr_list = new ArrayList<ReportData>();
		
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			ReportData rd = new ReportData();
			for (int j = 0; j < obj.length; j++) {
//				rd.setFrdateStr("" + obj[0]);
//				rd.setFcqxt("" + obj[1]);
//				rd.setFchxt1("" + obj[2]);
//				rd.setFchxt2("" + obj[3]);
			}
			xr_list.add(rd);
		}
		return xr_list;
	}
	
	
	
}
